package com.hand.control;


import com.hand.Dao.userDao;
import com.hand.domain.Role;
import com.hand.domain.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Collection;
import java.util.List;
import java.util.Locale;

@RestController
public class FindAll {

    @RequestMapping("/findAll")
    public List<User> findAll() throws IOException {

        InputStream resourceAsStream = Resources.getResourceAsStream("sqlMapConfig.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        userDao mapper = sqlSession.getMapper(userDao.class);

        //查询所有
        List<User> list = mapper.findAll();
        System.out.println(list);


        //根据role的编号查询
//        User user3 = new User();
//        user3.setUr_id(1);
//        List<User> userList = mapper.findByRoleId(user3);
//        System.out.println(userList);

        sqlSession.commit();
        sqlSession.close();
        return list;
    }


}
